import cv2
import numpy as np

from Config import img_path
#开。，先腐蚀-》扩张
img = cv2.imread(img_path)
img2 = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
#kernel = np.ones((2,2) ,np.uint8)

ret,dts1 = cv2.threshold(img2,90,255,cv2.THRESH_BINARY)

kernel = cv2.getStructuringElement(cv2.MORPH_RECT,(3,3))
#ret,dts1 = cv2.threshold(img2,85,255,cv2.THRESH_BINARY)
#dst = cv2.morphologyEx(dts1,cv2.MORPH_OPEN,kernel=kernel) #开。，先腐蚀-》扩张
#dst = cv2.morphologyEx(dts1,cv2.MORPH_CLOSE,kernel=kernel) #关。，先扩张-》腐蚀
#dst = cv2.morphologyEx(dts1,cv2.MORPH_GRADIENT,kernel=kernel) #梯度。，原图-腐蚀
#dst = cv2.morphologyEx(dts1,cv2.MORPH_TOPHAT,kernel=kernel) #顶帽。，原图-开运算
dst = cv2.morphologyEx(dts1,cv2.MORPH_BLACKHAT,kernel=kernel) #黑帽。，取噪点
#dst_1 = cv2.bitwise_not(dst)

#dst3 = cv2.bitwise_xor(dst_1,dts1)

cv2.imshow('img',img2)
cv2.imshow('dst1',dts1)
cv2.imshow('dst',dst)
cv2.waitKey(0)